package com.pandacc.service.fiction;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.context.WebApplicationContext;

import com.pandacc.dao.fiction.FictionChaptersDetailsDAO;
import com.pandacc.dao.fiction.FictionDetailsDAO;
import com.pandacc.pojo.fiction.FictionChaptersDetailsBean;
import com.pandacc.pojo.fiction.FictionDetailsBean;

/**
 * 处理小说章节详细信息的service层
 * 注意scope为singleton，不要用成员变量
 * @author Administrator
 *
 */
@Service("chapterService")
@Lazy
public class FictionChaptersDetailsService {
	
	/*//配合lookup-method使用
	public abstract FictionChaptersDetailsDAO getChapterDAO();
	public abstract FictionDetailsDAO getFictionDAO();*/
	
	@Lookup("chapterDAO")
	protected FictionChaptersDetailsDAO getChapterDAO(){return null;};
	@Lookup("fictionDAO")
	protected FictionDetailsDAO getFictionDAO(){return null;};

	/**
	 * 取小说基本信息和它的所有章节信息
	 * @param context
	 * @param factionId
	 * @return
	 */
	public FictionDetailsBean retrieveAllChapters(WebApplicationContext context, int factionId) {
		FictionDetailsBean fiction = getFictionDAO().retrieveFiction(context, factionId);
		List<String> chapters = getChapterDAO().retrieveAllChapters(context, factionId);
		fiction.setChapterList(chapters);
		return fiction;
	}

	/**
	 * 取小说单章节的详细信息
	 * @param context
	 * @param factionId
	 * @param chapterId
	 * @return
	 */
	public FictionChaptersDetailsBean retrieveChapter(int factionId,
			int chapterId) {
		FictionChaptersDetailsBean chapter = getChapterDAO().retrieveChapter(factionId, chapterId);
		return chapter;
	}
	
	public FictionChaptersDetailsBean retrieveChapter(WebApplicationContext context, int factionId,
			int chapterId) {
		FictionChaptersDetailsBean chapter = getChapterDAO().retrieveChapter(context, factionId, chapterId);
		return chapter;
	}

}
